import api from '@/api';

export default {
  namespace: 'sourceAccount',
  state: {
    sourceAccounts: {
      list: [],
      pagination: {},
    },
  },
  effects: {
    *fetchSourceAccount({ payload }, { call, put }) {
      const response = yield call(api.hui.sourceAccount.query, payload);
      const { errorCode, data: list, pagination } = response
      if (errorCode === 0) {
        yield put({
          type: 'saveSourceAccount',
          payload: {
            list,
            pagination,
          },
        });
      }
      return response
    },

  },
  reducers: {
    saveSourceAccount(state, { payload }) {
      return {
        ...state,
        sourceAccounts: payload,
      };
    },
  },

};
